

//https://www.ozon.ru/api/entrypoint-api.bx/page/json/v2?url=/product/1185794392/?layout_container=pdpPage2column&layout_page_index=2
function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    }
    return 0;
 }
 console.log("shein user size")

$(document).ready(function() {
    getStockByFetch();
});
function  getStockByFetch(msg){

    if(location.href.includes("www.shein.com.hk/risk/action/limit")){
        setTimeout(function() {
            window.close();
        }, 5000);
        return;
    }
    var bodyContent = $('body').text();
    console.log(bodyContent)

    var jsonObject = JSON.parse(bodyContent);

    if(jsonObject['code']=="200301"){
        var type = "sheindetaildel";
        var data={}
        data.id = getQueryString("bid");
        console.log(data);
        chrome.runtime.sendMessage({ data: {type,data }, close: false })
    }else if(jsonObject['info']['commentSizeRecommendInfo'] && jsonObject['info']['commentSizeRecommendInfo']['size_info_recommend_list']){

        var type = "shein_user_size";
        var id = getQueryString("bid");
        var user_size = jsonObject['info']['commentSizeRecommendInfo']['size_info_recommend_list'];
        console.log('sheinstock send.');
        chrome.runtime.sendMessage({ data: {type,id, user_size}, close: false });

    }

}

